package com.kbtd.service.mq;

import com.kbtd.entity.VoucherOrder;
import com.kbtd.service.IVoucherOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class VoucherOrderBlockConsumer implements Runnable {
    @Resource
    private IVoucherOrderService voucherOrderService;

    @Override
        public void run() {
            while (true) {
                try {
                    //1.获取队列中的信息
                    VoucherOrder voucherOrder = (VoucherOrder) BlockMQ.getMsgByType(BlockMQ.SECKILL_MESSAGE_TYPE)
                            .take();
                    //2.创建订单存到数据库
                    voucherOrderService.createVoucherOrder(voucherOrder);
                } catch (InterruptedException e) {
                    log.error("处理订单异常");
                }
            }
        }
    }